<?php if (!defined('THINK_PATH')) exit();?><section class="content-header" >
    <h1>
        任务管理
        <small>任务列表</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="<?php echo U('/Admin/index');?>"><i class="fa fa-home"></i>首页</a></li>
        <li class="active">任务管理</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <div class="box-title"><label >任务列表</label></div>
                    <div class="pull-right">
                        <div class="box-filter">
                            <form id="search_form">
                                <label>查找:</label>
                                <input type="text" name="report[start]" class="date" placeholder="任务开始日期">
                                <input type="text" name="report[end]" class="date" placeholder="任务结束日期">
                                <input type="text" name="report[task_from]" placeholder="装料站">
                                <input type="text" name="report[task_end]" placeholder="抵达地址">
                                <select name="report[status]" class="select2" onchange="search(this)">
                                    <option value="-1">---选择状态---</option>
                                    <option value="3">放弃</option>
                                    <option value="4">已完成</option>
                                </select>
                                <button class="btn btn-success " id="btnSearch">查询</button>
                                    <button class="btn btn-app " id="exportData"><i class="fa fa-area-chart"></i>导出数据</button>
                            </form>
                        </div>

                    </div>
                </div><!-- /.box-header -->
                <div class="box-body" style="margin-top: -60px">
                    <table id="table" class="table table-bordered table-striped" width="100%">
                        <thead>
                            <tr>
                                <th>装料站</th>
                                <th>抵达地址</th>
                                <th>安排车辆</th>
                                <th>方量</th>
                                <th>下达时间</th>
                                <th>接受时间</th>
                                <th>装料时间</th>
                                <th>发车时间</th>
                                <th>卸料时间</th>
                                <th>完成时间</th>
                                <th>状态</th>
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</section><!-- /.content -->
<!-- DATA TABES SCRIPT -->
<!-- page script -->
<script type="text/javascript">
    var taskTable = null;

    $(function () {
        $('.date').datepicker({language:'zh-CN','autoclose':true});
        $(".select2").select2({minimumResultsForSearch: -1});
        taskTable =  $('#table').dataTable({
            "autoWidth": true,
//            "order": [4,'desc'],
            "processing": true, //载入数据的时候是否显示“载入中”
            'ordering': false, //排序操作在服务端进行，所以可以关了。
            'serverSide': true,
            "searching": false,
            "ajax": {
                "url": "<?php echo U('Task/order');?>",
                "type": "POST"
            },
            "columns": [
                {"data": "task_from"},
                {"data": "task_end"},
                {"data": "car_name"},
                {"data": "total_load"},
                {"data": "public_time"},
                {"data": "start_time"},
                {"data": "load_time"},
                {"data": "depature_time"},
                {"data": "unloading_time"},
                {"data": "finish_time"},
                {"data": "status"}
            ],
            "columnDefs": [
                {
                    "targets": 0,
                    "render": function (data, type, row) {
                        return data+"<br/>装料口:"+row.load_site;
                    }
                },
                {
                    "targets": 1,
                    "render": function (data, type, row) {
                        return "联系人:"+row.linkman+",电话:"+row.mobile+"<br/>"+data;
                    }
                },
                {
                    "targets": 2,
                    "render": function (data, type, row) {
                        return data+"<br/>车号:"+row.car_no+"|载重:"+row.car_load;
                    }
                },
                {
                    "targets": 3,
                    "render": function (data, type, row) {
                        var types =['泵送','<span style="color:#0278C1">塔吊</span>','直卸','斗卸'];
                        var bd = '';
                        if(row.cost_load!=data){
                            bd = '&nbsp;<span style="color:red">保底:'+row.cost_load+"</span>";
                        }
                        return data+bd+"<br/>"+types[row.unload_type]+"<br/>标号:"+row.grade+"&nbsp;施工部位:"+row.components;
                    }
                },

                {
                    "targets": 10,
                    "render": function (data, type, row) {
                        if(data==0){
                            return "待开始";
                        }else if(data==1) {
                            return "<span style='color: blue;'>待执行</span>";
                        }else if(data==2){
                                return "<span style='color: green;'>执行中</span>";
                        }else if(data==3){
                            return "<span style='color: red;'>放弃</span><br/>"+row.note;
                        }else if(data==4){
                            var note = "";
                            if(row.note!=null){
                                note = "<br/>说明:"+row.note;
                            }
                            return "<span style='color: #1a68ff;'>已完成</span>"+note;
                        }
                    }
                }
            ],
            "language": lang
        });
        $('#btnSearch').click(function(){
            search();
            return false;
        });

        $('#exportData').click(function(){
            var api = taskTable.api();
            var data = $("#search_form").serialize()
//            alert("<?php echo U('Finance/cash');?>?"+data);
//            cash_dataTable.settings()[0].ajax.data = data;
            setTimeout(function(){
                location.href = "<?php echo U('Task/export_order_data');?>?"+data;
            },100);
            return false;
        });
    });


    function search() {
        var api = taskTable.api();
        var data = $("#search_form").serialize()
        api.ajax.url("<?php echo U('Task/order');?>?"+data);
        api.ajax.reload();
    }
</script>